Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@types/yargs
Advanced tools
The @types/yargs package provides TypeScript type definitions for the yargs library, which is a tool to help build interactive command line tools, by parsing arguments and generating an elegant user interface. It helps TypeScript developers to have auto-completion and type checking when using yargs.
Command Module Definition
Defines a command with options. This example creates a 'get' command with a required 'url' option.
import * as yargs from 'yargs';
yargs.command('get', 'make a get HTTP request', {
url: {
describe: 'URL to make request to',
demand: true,
alias: 'u',
type: 'string'
}
}, (argv) => {
console.log(`Making a GET request to: ${argv.url}`);
});
Option Parsing
Parses command line options. This example parses a boolean 'verbose' option.
import * as yargs from 'yargs';
const argv = yargs.option('verbose', {
alias: 'v',
type: 'boolean',
description: 'Run with verbose logging'
}).argv;
if (argv.verbose) console.log('Verbose mode on');
Help and Version Setup
Sets up automatic version and help message support. This example sets the version of the CLI tool and enables the default help support.
import * as yargs from 'yargs';
yargs.version('1.0.0').help().argv;
Commander is another popular npm package for building command line interfaces. It offers a high-level API for creating commands and options, similar to yargs. Commander is known for its simplicity and ease of use, but yargs provides more detailed control over argument parsing and generates more comprehensive help messages automatically.
Meow is a lighter alternative to yargs for building CLI tools. It focuses on simplicity and minimal configuration. While it is easier to set up for simple scripts, yargs offers more advanced features like command-specific options, middleware, and automatic help generation.
npm install --save @types/yargs
This package contains type definitions for yargs (https://github.com/chevex/yargs).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/yargs/v13.
These definitions were written by Martin Poelstra, Mizunashi Mana, Jeffery Grajkowski, Jimi (Dimitris) Charalampidis, Steffen Viken Valvåg, Emily Marigold Klassen, and ExE Boss.
FAQs
TypeScript definitions for yargs
We found that @types/yargs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.